home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 15327 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.3 KB  |  45 lines

  1. Path: morgan.cnu.edu!dlabell
  2. From: dlabell@pcs.cnu.edu (Daniel LaBell)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: casting a void pointer back to a function pointer
  5. Date: 04 Apr 1996 21:26:04 GMT
  6. Organization: not one of my strong points
  7. Message-ID: <DLABELL.96Apr4162605@sovereign.pcs.cnu.edu>
  8. References: <DLABELL.96Apr4021045@columbia.pcs.cnu.edu>
  9. NNTP-Posting-Host: sovereign.pcs.cnu.edu
  10. In-reply-to: dlabell@pcs.cnu.edu's message of 04 Apr 1996 07:10:45 GMT
  11.  
  12. (yes, I am answering my own post.)  A friend of mine checked a book,
  13. he had available at work, and gave me the synatax to declare a pointer
  14. to a type of function.
  15. this works:
  16. // Daniel LaBell
  17. // ~dlabell/C/test.cc
  18. #include <iostream.h>
  19. void foo1(){  cout << " foo1 " << endl; }
  20. void foo2(){  cout << " foo2 " << endl; }
  21. void foo3( int x )
  22. { cout << " foo3, argument = " << x << endl; }
  23. void do_a_foo( void (*fun)() )
  24. {  (*fun)(); }
  25. void do_a_foo( int x,  void (*fun) (int ) )
  26. {  fun ( x ); }
  27. int main()
  28. {
  29.   do_a_foo  ( foo1 );
  30.   void ( * funcP)()=foo2;
  31.   do_a_foo  (funcP);
  32.   void ( * funcP2)(int)=foo3;
  33.   do_a_foo  ( 2, funcP2 );
  34.   return 0;
  35. }
  36. Actually, this is wanted I wanted to do from the start, I just thought
  37. it wasn't possible.  So, I don't really need to know the syntax for
  38. the cast now, but if anyone knows it, I wouldn't mind adding it to 
  39. my bag of tricks. :)
  40.  
  41.  
  42.  
  43. --
  44. Daniel LaBell
  45.